package com.ellricky.excute_president

import android.app.Activity
import android.widget.ImageView
import android.widget.TextView
import androidx.cardview.widget.CardView
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.adapter.SmartViewHolder
import com.andr.common.util.EmptyUtil
import com.ellricky.baselib.entity.new.ComplainRecord
import com.ellricky.baselib.util.GlideUtil
import de.hdodenhof.circleimageview.CircleImageView


internal class WorkJoinAdapter(private val context: Activity) :
    BaseRecyclerAdapter<WorkJoinEntity>(R.layout.base_adapter_common_list) {

    override fun onBindViewHolder(vh: SmartViewHolder?, p1: WorkJoinEntity?, position: Int) {

        vh?.text(R.id.tvTitle, p1?.fromName)

        vh?.text(R.id.tvKey, context.getString(R.string.pd_work_join_to))
        vh?.text(R.id.tvValue, p1?.toName)

        vh?.text(R.id.tvDateKey, context.getString(R.string.pd_work_join_date))
        vh?.text(R.id.tvDate, p1?.changeToDate)
    }

}


internal class AmMeetingAdapter(private val context: Activity) :
    BaseRecyclerAdapter<AmMeetingRecordEntity>(R.layout.base_adapter_common_list) {

    override fun onBindViewHolder(vh: SmartViewHolder?, p1: AmMeetingRecordEntity?, position: Int) {

        vh?.text(R.id.tvTitle, p1?.meetTitle)

        vh?.text(R.id.tvKey, context.getString(R.string.pd_am_fz_teacher))
        vh?.text(R.id.tvValue, p1?.name)

        vh?.text(R.id.tvDateKey, context.getString(R.string.pd_am_date))
        vh?.text(R.id.tvDate, p1?.meetDate)
    }

}


internal class PdLeaveApplyAdapter(private val context: Activity) :
    BaseRecyclerAdapter<PdLeaveEntity>(R.layout.base_adapter_common_list) {

    override fun onBindViewHolder(vh: SmartViewHolder?, p1: PdLeaveEntity?, position: Int) {

        val itemView = vh?.itemView
        itemView?.let {
            val rootView = it.findViewById<CardView>(R.id.cvRoot)
            val tvtitle = it.findViewById<TextView>(R.id.tvTitle)
            val tvKey = it.findViewById<TextView>(R.id.tvKey)
            val tvValue = it.findViewById<TextView>(R.id.tvValue)
            val tvDateKey = it.findViewById<TextView>(R.id.tvDateKey)
            val tvDate = it.findViewById<TextView>(R.id.tvDate)
            val ivEnd = it.findViewById<ImageView>(R.id.ivEnd)

            var approved = false
            when (p1?.approveStatus) {
                LEAVE_APPLY_AGREE, LEAVE_APPLY_REFUSE -> {
                    approved = true
                }
            }

            rootView?.isSelected = approved
            tvtitle.isSelected = approved
            tvKey.isSelected = approved
            tvValue.isSelected = approved
            tvDateKey.isSelected = approved
            tvDate.isSelected = approved
            if (approved) ivEnd.setImageResource(R.drawable.base_icon_common_list_white)
            else ivEnd.setImageResource(R.drawable.base_icon_common_list)

            tvtitle.text = p1?.name

            tvKey.text = context.getString(R.string.pd_leave_fz_class)
            tvValue.text = p1?.className

            tvDateKey.text = context.getString(R.string.pd_leave_type)
            tvDate.text = p1?.leaveType
        }

    }

}

internal class PdTaskAdapter(private val context: Activity) :
    BaseRecyclerAdapter<PdTaskEntity>(R.layout.base_adapter_common_list) {

    override fun onBindViewHolder(vh: SmartViewHolder?, p1: PdTaskEntity?, position: Int) {

        vh?.text(R.id.tvTitle, p1?.title)

        vh?.text(R.id.tvKey, context.getString(R.string.pd_fz_teacher))
        vh?.text(R.id.tvValue, p1?.name)

        vh?.text(R.id.tvDateKey, "")
        vh?.text(R.id.tvDate, p1?.startDate + "-" + p1?.endDate)
    }

}


internal class AchieveAdapter(private val context: Activity) :
    BaseRecyclerAdapter<AchieveEntity>(R.layout.pd_adapter_achieve) {

    override fun onBindViewHolder(vh: SmartViewHolder?, p1: AchieveEntity?, position: Int) {
        val cv = vh?.itemView?.findViewById<CircleImageView>(R.id.ivAvatar)
        cv.let {
            GlideUtil.into(context, p1?.headPic, it)
        }

        vh?.text(R.id.tvUserName, p1?.name)
        vh?.text(R.id.tvNum, p1?.nowStudent)

    }
}

internal class TyCourseAdapter(private val context: Activity) :
    BaseRecyclerAdapter<TyCourseEntity>(R.layout.base_adapter_common_list) {

    override fun onBindViewHolder(vh: SmartViewHolder?, p1: TyCourseEntity?, position: Int) {

        var title = p1?.classTypeName ?: ""
        if (EmptyUtil.isEmpty(p1?.preId)) {
            title = title.plus("（未备课）")
        }
        vh?.text(R.id.tvTitle, title)

        vh?.text(R.id.tvKey, context.getString(R.string.pd_fz_teacher))
        vh?.text(R.id.tvValue, p1?.name)

        vh?.text(R.id.tvDateKey, context.getString(R.string.pd_course_open_time))
        vh?.text(R.id.tvDate, p1?.temClassDate)
    }

}

internal class KxAdapter(private val context: Activity) :
    BaseRecyclerAdapter<TodayKxEntity>(R.layout.base_adapter_common_list) {

    override fun onBindViewHolder(vh: SmartViewHolder?, p1: TodayKxEntity?, position: Int) {

        vh?.text(R.id.tvTitle, p1?.classTypeName)

        vh?.text(R.id.tvKey, context.getString(R.string.base_class))
        vh?.text(R.id.tvValue, p1?.className)

        vh?.text(R.id.tvDateKey, context.getString(R.string.pd_fz_teacher))
        vh?.text(R.id.tvDate, p1?.name)
    }

}

internal class VipAdapter(private val context: Activity) :
    BaseRecyclerAdapter<VipEntity>(R.layout.pd_adapter_achieve) {

    override fun onBindViewHolder(vh: SmartViewHolder?, p1: VipEntity?, position: Int) {
        val cv = vh?.itemView?.findViewById<CircleImageView>(R.id.ivAvatar)
        cv.let {
            GlideUtil.into(context, p1?.headPic, it)
        }

        vh?.text(R.id.tvUserName, p1?.name)
        vh?.text(R.id.tvNum, p1?.age.plus("岁"))

    }
}

internal class WorkLogAdapter :
    BaseRecyclerAdapter<WorkLogListEntity>(R.layout.pd_adapter_work_log) {
    override fun onBindViewHolder(vh: SmartViewHolder?, p1: WorkLogListEntity?, position: Int) {
        vh?.let {
            it.text(R.id.tvTitle, p1?.name)
            it.text(R.id.tvNum, p1?.count)
            it.text(R.id.tvUnit, p1?.unit)
        }
    }
}

internal class IncomeAdapter :
    BaseRecyclerAdapter<IncomeEntity>(R.layout.pd_adapter_income) {
    override fun onBindViewHolder(vh: SmartViewHolder?, p1: IncomeEntity?, position: Int) {
        vh?.let {
            val tvL = it.itemView.findViewById<TextView>(R.id.tvL)
            val tvC = it.itemView.findViewById<TextView>(R.id.tvC)
            val tvR = it.itemView.findViewById<TextView>(R.id.tvR)

            tvL.text = p1?.name
            tvC.text = p1?.price
            tvR.text = p1?.priceDate
        }
    }
}



